package com.immunology.database.transformers;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.log4j.Logger;

import com.immunology.core.BaseTransformer;
import com.immunology.database.DbColumns;
import com.immunology.model.User;
import com.immunology.model.enums.Role;

public class UserTransformer extends BaseTransformer<User>{
	private static final Logger LOG = Logger.getLogger(UserTransformer.class);

	@Override
	public User transformTo(ResultSet resultSet) {
		User user = new User();
		try {
			user.setId(resultSet.getInt(DbColumns.FIRST_COLUMN));
			user.setFirstName(resultSet.getString(DbColumns.SECOND_COLUMN));
			user.setMiddleName(resultSet.getString(DbColumns.THIRD_COLUMN));
			user.setLastName(resultSet.getString(DbColumns.FOURTH_COLUMN));
			user.setLogin(resultSet.getString(DbColumns.FIFTH_COLUMN));
			user.setPassword(resultSet.getString(DbColumns.SIXTH_COLUMN));
			user.setRole(Role.fromValue(resultSet.getString(DbColumns.SEVENTH_COLUMN)));
			user.setPost(resultSet.getString(DbColumns.EIGHTH_COLUMN));
		} catch (SQLException e) {
			LOG.error("Can't create UserTransformer object:", e);
		}
		return user;
	}

}
